package com.example.bzh.gamecat.ui.society.babysociety;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.bzh.gamecat.R;
import com.example.bzh.gamecat.bean.IconListBean;
import com.example.bzh.gamecat.bean.SocietyAllPlayBean;
import com.example.bzh.gamecat.bean.SocietyBabyListBean;

import java.util.List;

/**
 * Created by MyPC on 2016/8/17.
 */
public class SocietyBabyAdapter extends BaseAdapter{

    private Context context;
    private List<SocietyBabyListBean> list;

    public SocietyBabyAdapter(Context context, List<SocietyBabyListBean> list){
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {

        ViewHolder holder;
        if (view == null){
            view = LayoutInflater.from(context).inflate(R.layout.babysociety_list_item,null);
            holder = new ViewHolder(view);
            view.setTag(holder);
        }else{
            holder = (ViewHolder) view.getTag();
        }

        SocietyBabyListBean societyBabyListBean = list.get(position);
        holder.tvName.setText(societyBabyListBean.getBabyname());
        holder.tvSociety.setText(societyBabyListBean.getGuildName());
        List<IconListBean> iconList = societyBabyListBean.getIconList();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < iconList.size(); i++) {
            if (i == 0){
                sb.append(iconList.get(i).getName());
            }else{
                sb.append(";"+iconList.get(i).getName());
            }
        }

        holder.tvPlay.setText(sb);

//        holder.tvLoveNum.setText(societyBabyListBean.getFollowNum());

        Glide.with(context).load(societyBabyListBean.getHeadphoto()).into(holder.ivLogo);


        return view;
    }

    class ViewHolder{

        private ImageView ivLogo,ivLove;
        private TextView tvName,tvSociety,tvPlay,tvLoveNum;
        private RelativeLayout rlAddFriend;
        public ViewHolder(View view){
            ivLogo = (ImageView) view.findViewById(R.id.iv_baby_logo);
            ivLove = (ImageView) view.findViewById(R.id.iv_baby_love);

            tvName = (TextView) view.findViewById(R.id.tv_baby_name);
            tvSociety = (TextView) view.findViewById(R.id.tv_baby_society);
            tvPlay = (TextView) view.findViewById(R.id.tv_baby_play);
            tvLoveNum = (TextView) view.findViewById(R.id.tv_baby_love_num);

            rlAddFriend = (RelativeLayout) view.findViewById(R.id.rl_add_friend);
        }

    }


}
